package com.jic.order.controller.manage;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.order.entity.OrderError;
import com.jic.order.manage.request.OrderErrorRequest;
import com.jic.order.manage.response.OrderErrorResponse;
import com.jic.order.service.OrderErrorService;
import com.jic.order.utils.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by HeJun on 2020/2/29
 *
 * @Description:
 */
@Api(tags = "订单异常")
@RestController
@RequestMapping("/orderError")
@Slf4j
public class OrderErrorController {

    @Autowired
    OrderErrorService orderErrorService;

    @ApiOperation(value = "获取订单异常信息")
    @PostMapping("/queryPage")
    public RestResult<PageResult<OrderErrorResponse>> query(@RequestBody OrderErrorRequest oer) {
        PageResult<OrderErrorResponse> result = orderErrorService.queryPage(oer);
        return RestResult.success(result);
    }

    @ApiOperation(value = "获取订单异常信息", notes = "获取订单异常信息")
    @PostMapping("/update")
    public RestResult<Long> update(@RequestBody OrderErrorRequest obdr) {
        OrderError orderError = BeanUtil.copy(obdr, OrderError.class);
        orderError.setRemarkStatus(orderError.getRemarkStatus() == 1 ? 2 : 1 );
        long result = 0;
        for (int i = 0; i < obdr.getIds().length; i++) {
            orderError.setId(obdr.getIds()[i]);
            result = orderErrorService.update(orderError);
        }
        return RestResult.success(result);
    }
}

